package com.atguigu.bean;

import java.util.List;

/**
 * @ Author:任留辉
 * @ Description:封装一系列和分页有关的数据
 * @ Date:Created in 20:56 2021/3/17 0017
 */
public class Page<T> {
    //从浏览器获取的字符串类型的当前页的页码
    private String pageNoStr;
    //每页显示的条数
    private Integer pageSize;
    //总记录数
    private Integer count;
    //转换为Integer类型的当前页的页码
    private Integer pageNo;
    //总页数
    private Integer totalPage;
    //分页之后的数据对应的list集合
    private List<T> list;

    public String getPageNoStr() {
        return pageNoStr;
    }

    public void setPageNoStr(String pageNoStr) {
        this.pageNoStr = pageNoStr;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getCount() {
        return count;
    }

    public void setCount(Integer count) {
        this.count = count;
    }

    public Integer getPageNo() {
        pageNo = 1;
        try {
            pageNo = Integer.parseInt(pageNoStr);
        } catch (NumberFormatException e) { }
        if(pageNo <= 0){
            pageNo = 1;
        }
        if(pageNo > getTotalPage()){
            pageNo = getTotalPage();
        }
        return pageNo;
    }

    public void setPageNo(Integer pageNo) {
        this.pageNo = pageNo;
    }

    public Integer getTotalPage() {
        totalPage = 0;
        if(count % pageSize == 0){
            totalPage = count / pageSize;
        }else{
            totalPage = count / pageSize + 1;
        }
        return totalPage;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }


}
